-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users to opt-out of changing instance name tags #3
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This pull request introduces a new feature allowing users to opt-out of changing instance name tags in Auto Scaling Groups (ASGs). The changes primarily affect the README.md and lambda/autoscale/autoscale.py files.
- Added new
asg:update_instance_name
tag inlambda/autoscale/autoscale.py
to control instance name tag updates - Updated
README.md
with documentation on how to use the new opt-out feature - Modified
fetch_tag_metadata
andprocess_message
functions inlambda/autoscale/autoscale.py
to implement the opt-out logic - CHANGELOG.md should be updated to reflect this new feature
- Consider adding tests for the new opt-out functionality
2 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings
tags = autoscaling.describe_tags( | ||
Filters=[ | ||
{'Name': 'auto-scaling-group','Values': [asg_name]}, | ||
{'Name': 'key','Values': [HOSTNAME_TAG_NAME]} | ||
{'Name': 'key','Values': [HOSTNAME_TAG_NAME, UPDATE_INSTANCE_TAG_NAME]} | ||
], | ||
MaxRecords=1 | ||
)['Tags'][0]['Value'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The 'Tags' key is accessed without checking if it exists or if it's empty. This could lead to an IndexError if no tags are found.
tag_values = { | ||
tag['Key']: tag['Value'] for tag in tags | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This dictionary comprehension assumes that 'tags' is a list of dictionaries with 'Key' and 'Value' keys. However, 'tags' is actually the value of the first tag found. This will likely cause a runtime error.
if asg_tag_metadata.get(UPDATE_INSTANCE_TAG_NAME, "true") == "true": | ||
update_name_tag(instance_id, hostname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The default value 'true' is a string, not a boolean. Consider using a boolean default value instead.
@@ -12,6 +12,7 @@ | |||
route53 = boto3.client('route53') | |||
|
|||
HOSTNAME_TAG_NAME = "asg:hostname_pattern" | |||
UPDATE_INSTANCE_TAG_NAME = "asg:update_instance_name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a comment explaining the purpose and expected values of UPDATE_INSTANCE_TAG_NAME for better code documentation.
I was very surprised when my instance names changed after adding this. I much prefer their original names, so I added a way to opt-out of of them being change. 😄